<template>
  <div class="container-fluid">
    <div class="row mga box-top">
      <div class="col">
        <div class="Suspension" v-if="getuser.usertype === 'Admin'">
          <a href="/admin.html#/user" target="_blank" rel="noopener noreferrer">
            <el-button>
              <img
                src="https://hterobot-kimage.oss-cn-qingdao.aliyuncs.com/images1/logo0200.png"
                style="width:46px"
                alt
              />
            </el-button>
          </a>
        </div>
        <div class="container-fluid">
          <h3 class="h3 row">学习进度</h3>
          <div class="row">
            <div class="col">
              <div class="card pull-left" v-for="(v, i) in userCatebag" :key="`1myhome${i}`">
                <router-link :to="{name: 'typeclass',params:{id:v.ID}}">
                  <img
                    class="card-img-top"
                    :src="v.banner+'?x-oss-process=style/style-400'"
                    alt="Card image cap"
                  />
                </router-link>
                <div class="card-body card-text" style="padding:6px 10px;">
                  <h6 class="card-title" v-text="v.name"></h6>
                  <div class="card-text">
                    <el-progress
                      :show-text="false"
                      :text-inside="true"
                      color="#2f81f1"
                      :percentage="percentage(v.ID)"
                      :stroke-width="3"
                    ></el-progress>
                  </div>
                  <div class="card-text text-right text-12">已学习{{percentage(v.ID)}}%</div>
                </div>
              </div>
            </div>
            <div class="cold" v-if="!userCatebag.length">
              <h5 class="text-center tecenter">没有课程</h5>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row mga padds">
      <div class="col">
        <div class="container-fluid">
          <h3 class="h3 row">我的班级</h3>
          <div class="row">
            <div class="col">
              <h5 class="text-center tecenter">暂无班级</h5>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row mga padds">
      <div class="col">
        <div class="container-fluid">
          <h3 class="h3 row">我的作品</h3>
          <div class="row">
            <div class="col">
              <h5 class="text-center tecenter">创建一个作品吧</h5>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import _ from "underscore";
export default {
  data() {
    return {
      userCatebag: [],
      dialogVisiblet: false
    };
  },
  computed: mapGetters([
    "getuser",
    "getCourse",
    "getuserCourse",
    "getCatebag",
    "getuserUserCourse",
    "getCoursecatebag"
  ]),
  mounted() {
    let arr = [];
    this.userCatebag = [];
    for (let v of this.getuserUserCourse) {
      arr.push(v.course_ID);
    }

    arr = _.filter(this.getCoursecatebag, u => {
      if (_.indexOf(arr, u.cid) != -1) {
        return true;
      }
    });

    arr = _.map(arr, v => v.catebagid);
    arr = _.filter(this.getCatebag, u => {
      if (_.indexOf(arr, u.ID) != -1) {
        return u;
      }
    });
    if (arr.length > 3) {
      arr = arr.splice(0, 3);
    }
    this.userCatebag = arr;
  },
  methods: {
    percentage(ID) {
      let fenmu = _.find(this.getCatebag, u => {
        return ID == u.ID;
      });
      let arr = [];
      for (let v of this.getuserUserCourse) {
        arr.push(v.course_ID);
      }
      let fenzi = _.filter(this.getCoursecatebag, u => {
        if (ID == u.catebagid) {
          if (_.indexOf(arr, u.cid) != -1) {
            return u;
          }
        }
      });
      let data = parseInt((fenzi.length / fenmu.count) * 100);
      return data > 100 ? 100 : data;
    }
  }
};
</script>

<style scoped>
.box-top {
  height: 292px;
}
.h3 {
  height: 18px;
  font-size: 18px;
  font-weight: 600;
  color: #2f81f1;
  margin-bottom: 27px;
}
.el-progress {
  padding-bottom: 10px;
}
.mga {
  background-color: #ffffff;
  box-shadow: 0px 0px 21px 0px rgba(0, 0, 0, 0.07);
  border-radius: 10px;
  padding: 20px;
  min-height: 200px;
  font-family: MicrosoftYaHei-Bold;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  color: #666666;
}
.card {
  width: 232px;
  margin: 0 10px;
  box-shadow: 0px 5px 8px 0px rgba(0, 0, 0, 0.02);
  border-color: #ffffff;
  border-radius: 6px;
}
.tecenter {
  line-height: 120px;
  color: #333333;
  font-size: 16px;
}

.text-12 {
  font-size: 12px;
  color: #999999;
  line-height: 20px;
}
.card-text {
  line-height: 20px;
}
.cold {
  -webkit-box-flex: 1;
  flex-grow: 94;
  max-width: 100%;
}
.Suspension {
  position: fixed;
  z-index: 1;
  width: 136px;
  top: 80%;
  right: 52px;
  margin: auto;
  margin-left: 10px;
  width: 42px;
  height: 60px;
  border: 1px solid block;
}
</style>